/**
* @Author:		Nguyen Duy	<tratstil@gmail.com>
* 2011 - For a Profession Style
*/
#pragma once
#include "CGame.h"
#if !defined(_H_TESTER)
#define _H_TESTER

#if TESTER
#define Game CGame::_this
#define TesterReady !Tester::_this->tfisrtrun
#define Ter Tester::_this

/*<tester attribute>*/
#define TBUTTON_W	30
#define TBUTTON_H	20

#define TBegin	0
#define TEnd	1

#define TEST_BG_COLOR		0xFF6E7B8B	//bg use on TEST_MODE
#define TEST_FILL_COLOR		0x55B0C4DE	// fill color
#define TEST_BORDER_COLOR	0x55458B74	// border color


/*</tester attribute>*/

/*<invironment>*/
/**
*	TEST_MODE:
*	1: Open Test mode that only show test layer, all touch to game mode will had been cancel.
*/
	#define TEST_MODE 0
/*</invironment>*/

/*<feature on off>*/
#define TF_DEF_LOG	1
/*</feature on off>*/



/***************************************************************************
* feature config>*/
	/*<Tlog>*/
		#define TLOG_DEF_OPACITY	100
		#define TLOG_DEF_ZOOM		1.0f
	/*</Tlog>*/
/*feature config
*****************************************************************************/
/*<define class for tester>*/
class TestModule
{
public:
	char* name;
	virtual void InitTestModule()=0;	//on init . called by tester after adding module.
	virtual void UpdateTestModule()=0;	// on updating
	virtual void RenderTestModule()=0; // on rendering
	virtual bool UpdateTouchTestModule(int x, int y, int type)=0; // when touch
	virtual void Active()=0; // when has focus.
	virtual void Inactive()=0; // when lost focus.
};

#if defined(USE_SOCIAL_NETWORK) && defined(USE_CPAGE)
class tPageScocial:CPage{
private:
	RectStream Canvas;
public:
	void init();	//on init .
	void update();	// on updating
	void render(GLESLib* g); // on rendering
	bool updateTouch(int x, int y, int type); // when touch
	void release();
	void setCanvas(RectStream canvas);
};
#endif
/*<define class for tester>*/

class Tester
{
private:
	Tester();
public:	
	bool tfisrtrun;
	static Tester* _this;
	
	~Tester(void);
/*<core of tester>*/
	GLESLib* _g;
	bool _Tpage;
	CSprite* fwhite;	//font white
	CSprite* fyellow;	//font yellow
	CSprite* fgreen;	//font green
	CSprite* fred;		//font red
	void Run();
	void UpdateTouch();
	static Tester* GetTesterInstance();
	void InitTester();
	void ResetTester();
	void RenderTester();
	void UpdateTester();
	float tangle;
private:
public:
/*</core of tester>*/
/*<feature>*/
	#define TFLOG				0
	//----------------------------------
	#define TFEATURE_NUM		1
	
	#define IsFeatureLock(F)(TFEATURE_LOCK[F])
	char fName[TFEATURE_NUM][254];

	void tLockFeature(int Feature);
	void tUnLockFeature(int Feature);
	//------------------------------------
    RectStream _Trec_ctrl;//control bar;
    static RectStream _Trec_ctrl_button;//control button;
    static RectStream _Trec_mod_ctrl;
    static TextButtonStream* _Trec_mods;
	//------------------------------------
private:
	bool TFEATURE_LOCK[TFEATURE_NUM];
public:
/*</feature>*/
/*<dynamic module control>*/
	#define TESTER_MODULE_LENGTH	10	
	TestModule* tModule[TESTER_MODULE_LENGTH];
	bool tb_mInUse[TESTER_MODULE_LENGTH];// show which offset of module array has being used.
	char tc_mName[TESTER_MODULE_LENGTH][50];// hold the name of module.
	int ti_mActive;// the offset of active module in module array.
	int AddTestModule(TestModule* ctModule);
	int ti_mNum;
/*</dynamic module control>*/
	int GetFontHeight(CSprite* spr);
    
/*<tlog>*/
#define TLOG_ELEMENT	200
#define TLOG_LENGTH		200
#define	TLOG_LEFT_WIDTH	25
#define TLOG_BUTTON_NUM 1
    
	char _Tlog[TLOG_ELEMENT][TLOG_LENGTH];
	int _Ttype[TLOG_ELEMENT];
	int _Tlog_h[TLOG_ELEMENT];

	bool _log_init;
	int _cur_log;
	float _log_scrolly;
	int _Tlog_total_h;
	float _log_mousedown_y;
	float _log_delta_y;
	bool _log_can_scroll;
    
	void InitTLog();
	void RenderTLog();
	void UpdateTLog();
	bool UpdateTouchTLog(int tx, int ty, int type);
	void TLog(char* LogStr,int type = 0);
	void TLog(int type,const char* format, ...);
	void TlogClear();
    
	RectStream _Tlog_rec;
#if defined(USE_SOCIAL_NETWORK) && defined(USE_CPAGE)
	tPageScocial* TestSocialPage;
#endif
/*</tlog>*/
};
#endif //TESTER
#endif //_H_TESTER